package cn.wit.summit.chwan.adapters;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import cn.wit.summit.chwan.R;
import cn.wit.summit.chwan.models.dto.CommentBaseBean;
import cn.wit.summit.chwan.models.dto.GameInfoDetial;
import cn.wit.summit.chwan.models.dto.JumpBaseBean;
import cn.wit.summit.chwan.tools.webview.WebJSPInterfaceMethedBean;
import cn.wit.summit.chwan.tools.webview.WebViewClientYQW;
import cn.wit.summit.chwan.ui.activity.ImagePagerActivity;
import cn.wit.summit.chwan.utils.AccountUtil;
import cn.wit.summit.chwan.utils.DateUtils;
import cn.wit.summit.chwan.utils.IntentUtil;
import cn.wit.summit.chwan.utils.NetWorkUtils;
import cn.wit.summit.chwan.utils.StringUtils;
import cn.wit.summit.chwan.utils.UtilsMy;
import cn.wit.summit.chwan.viewholder.ViewHolderGameDetialMain;
import cn.wit.summit.chwan.widgets.MStarBar;
import cn.wit.summit.chwan.widgets.ObservableWebView;
import cn.wit.summit.chwan.widgets.VipView;
import it.sephiroth.android.library.widget.HListView;

/**
 * Created by yangg on 2018/4/12.
 */

public class DetailFragmentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    Activity mContext;
    Listener mListenr = null;
    GameInfoDetial gameInfoDetial;

    private List<String> strings = new ArrayList<String>();
    private List<GamedetialItemMain> gameListdata;

    public DetailFragmentAdapter(Activity context, GameInfoDetial gameInfoDetial) {
        this.mContext = context;
        this.gameInfoDetial = gameInfoDetial;
        gameListdata = new ArrayList<>();
    }


    public List<GamedetialItemMain> getlistData() {
        return gameListdata;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        ViewHolderGameDetialMain holder = null;
        switch (viewType) {
            case ViewType.ADVIEW:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.gamedetail_ad_item, parent, false);
                holder = new ViewHolderAD(view);
                break;
            case ViewType.ITEMTITLE:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.gamedetail_item_title, parent, false);
                holder = new ViewHolderGTitle(view);
                break;
            case ViewType.IMAGES:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.gamedetail_item_viewpage, parent, false);
                holder = new ViewHolderGViewPage(view);
                break;
            case ViewType.DESCRIBE:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.gamedetail_item_describ, parent, false);
                holder = new ViewHolderGGameDescribe(view);
                break;
            case ViewType.COMMENTITEM:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.comment_list_item_new_view, parent, false);
                holder = new CommentViewHolder(view);
                break;

            case ViewType.NO_COMMIT:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.gamedetail_none_comment_layout, parent, false);
                holder = new ViewHolderNO_COMMIT(view);
                break;

            case ViewType.COMMIT_FOOTER:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.gamedetail_item_commit_footer, parent, false);
                holder = new ViewHolderGCommitFoot(view);
                break;
            case ViewType.WEBVIEW:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.gamedetail_item_webview, parent, false);
                holder = new ViewHolderWEB(view);
                break;
        }


        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        switch (getItemViewType(position)) {
            case ViewType.ITEMTITLE:
                ViewHolderGTitle holderGTitle = (ViewHolderGTitle) holder;
                GamedetialItemMain itemMain = gameListdata.get(position);

                if (itemMain.object instanceof String) {
                    holderGTitle.titleText.setText((String) itemMain.object);
                }
                break;
            case ViewType.ADVIEW:
                ViewHolderAD holderAD = (ViewHolderAD) holder;
                holderAD.scrollViewAd.removeAllViews();
                for (final JumpBaseBean jumpBaseBean : gameInfoDetial.getGame_prize_ad()) {
                    View view = LayoutInflater.from(mContext).inflate(R.layout.gamedetail_ad_item_child, null);
                    TextView titleText = view.findViewById(R.id.titleText);
                    TextView contentText = view.findViewById(R.id.contentText);
                    view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            IntentUtil.getInstance().intentTo(mContext, jumpBaseBean);
                        }
                    });
                    titleText.setText(jumpBaseBean.getJump_sub_title());
                    contentText.setText(jumpBaseBean.getJump_label());
                    holderAD.scrollViewAd.addView(view);

                }
                break;
            case ViewType.IMAGES:
                ViewHolderGViewPage holderGViewPage = (ViewHolderGViewPage) holder;
                if (strings.size() == 0) {
//                     if (StringUtils.isNotEmpty(gameInfoDetial.getVedio_cover_pic()) && StringUtils.isNotEmpty(modleFourBean.getVedio_url())) {
//                         strings.add(modleFourBean.getVedio_cover_pic());
//                         isVideo = true;
//                     } else {
//                         isVideo = false;
//                     }

                    if (gameInfoDetial != null) {
                        if (gameInfoDetial.getGame_slide_pic() != null) {

                            strings = gameInfoDetial.getGame_slide_pic().getPic_list();
                        }
                    }
                    if (strings.size() == 0) {
                        holderGViewPage.screenListView.setVisibility(View.GONE);
                    } else {
                        holderGViewPage.screenListView.setVisibility(View.VISIBLE);
                        int pic_position = gameInfoDetial.getGame_slide_pic().getPic_position();
                        if (holderGViewPage.screenListView.getAdapter() == null) {
                            GameDetailAdapter gameDetailAdapter = new GameDetailAdapter(holderGViewPage.screenListView.getContext(), pic_position, strings, false);
                            holderGViewPage.screenListView.setAdapter(gameDetailAdapter);
                            holderGViewPage.screenListView.setOnItemClickListener(new it.sephiroth.android.library.widget.AdapterView.OnItemClickListener() {
                                @Override
                                public void onItemClick(it.sephiroth.android.library.widget.AdapterView<?> parent, View view, int position, long id) {
                                    try {
                                        Intent intent = new Intent(view.getContext(), ImagePagerActivity.class);
                                        // 图片url,为了演示这里使用常量，一般从数据库中或网络中获取
                                        String[] urls = new String[strings.size()];
                                        for (int i = 0; i < strings.size(); i++) {
                                            urls[i] = strings.get(i);
                                        }
                                        intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, urls);
                                        intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, position);
                                        view.getContext().startActivity(intent);

                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            });

                        }
                    }
                }
                break;
            case ViewType.DESCRIBE:
                final ViewHolderGGameDescribe holderGDescribe = (ViewHolderGGameDescribe) holder;
                holderGDescribe.htmlGameDescribe.setText(Html.fromHtml(gameInfoDetial.getGame_introduce()), TextView.BufferType.SPANNABLE);

                final ViewHolderGGameDescribe finalCommentViewHolderx = holderGDescribe;
                ViewTreeObserver observer = finalCommentViewHolderx.htmlGameDescribe.getViewTreeObserver();
                observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    boolean isfirstRunning = true;

                    @Override
                    public void onGlobalLayout() {
                        if (isfirstRunning == false) return;
                        Layout l = finalCommentViewHolderx.htmlGameDescribe.getLayout();
                        if (l != null) {
                            int lines = l.getLineCount();
                            if (lines > 4) {
                                holderGDescribe.textMore.setVisibility(View.VISIBLE);
                            } else if (lines > 0) {
                                if (l.getEllipsisCount(lines - 1) > 0) {
                                    holderGDescribe.textMore.setVisibility(View.VISIBLE);
                                } else {
                                    holderGDescribe.textMore.setVisibility(View.GONE);
                                }
                            }
                            isfirstRunning = false;
                        } else {
                            holderGDescribe.textMore.setVisibility(View.GONE);
                        }
                    }
                });
                holderGDescribe.textMore.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        String s = holderGDescribe.textMore.getText().toString();
                        if (s.equals("展开")) {
                            holderGDescribe.htmlGameDescribe.setMaxLines(Integer.MAX_VALUE);
                            holderGDescribe.textMore.setText("收起");
                        } else {
                            holderGDescribe.htmlGameDescribe.setMaxLines(4);
                            holderGDescribe.textMore.setText("展开");
                        }
                    }
                });
                break;
            case ViewType.COMMENTITEM:
                try {
                    GamedetialItemMain itemMainx = gameListdata.get(position);
                    if (itemMainx == null) return;
                    final CommentBaseBean commitDataBean = (CommentBaseBean) itemMainx.object;
//                     ViewBean.Comment viewBean = (ViewBean.Comment) getItem(position);
//                     final CommentBaseBean commitDataBean = viewBean.data;
                    CommentViewHolder commentViewHolder = (CommentViewHolder) holder;

                    if (commitDataBean.getUid().equals(String.valueOf(AccountUtil.getInstance().getUid()))) {
                        commentViewHolder.isMe.setVisibility(View.VISIBLE);
                    } else {
                        commentViewHolder.isMe.setVisibility(View.GONE);
                    }

                    if (StringUtils.isEmpty(commitDataBean.getUser_name())) {
                        commentViewHolder.userName.setVisibility(View.GONE);
                    } else {
                        commentViewHolder.userName.setVisibility(View.VISIBLE);
                        commentViewHolder.userName.setText(commitDataBean.getUser_name());
                    }
                    if (android.os.Build.VERSION.SDK_INT == 19) {
                        commentViewHolder.content.setText(commitDataBean.getContent().replaceAll("\n", ""));
                    } else {
                        commentViewHolder.content.setText(commitDataBean.getContent());
                    }
                    if (commitDataBean.getIs_old() == 1 || commitDataBean.getMobile_phone_model() == null
                            || commitDataBean.getMobile_phone_model().isEmpty())
                        commentViewHolder.phoneModle.setVisibility(View.INVISIBLE);
                    else {
                        commentViewHolder.phoneModle.setVisibility(View.VISIBLE);
                        commentViewHolder.phoneModle.setText(commitDataBean.getMobile_phone_model());
                    }
                    commentViewHolder.pariseNumber.setText(commitDataBean.getPraise_count() + "");
                    commentViewHolder.downNumber.setText(commitDataBean.getDespise_count() + "");
                    commentViewHolder.messageNumber.setText(commitDataBean.getReply_count() + "");
                    long timel = Long.parseLong(commitDataBean.getAdd_times() + "000");
                    commentViewHolder.time.setText(DateUtils.FormatForDownloadTime(timel));

                    if (commitDataBean.getApproval_rate() != null
                            && Double.valueOf(commitDataBean.getApproval_rate()) > 70)
                        commentViewHolder.isGood.setVisibility(View.VISIBLE);
                    else
                        commentViewHolder.isGood.setVisibility(View.GONE);

                    if (commitDataBean.getIs_praise() == 1) {
                        commentViewHolder.parise.setImageResource(R.drawable.uped_ic);
                    } else {
                        commentViewHolder.parise.setImageResource(R.drawable.up_ic);
                    }

                    if (commitDataBean.getIs_despise() == 1) {
                        commentViewHolder.down.setImageResource(R.drawable.downed_ic);
                    } else {
                        commentViewHolder.down.setImageResource(R.drawable.down_ic);
                    }

                    UtilsMy.setIconImage(mContext, commitDataBean.getHead_portrait(), commentViewHolder.userIcon);
                    setOnPraiseListener(commentViewHolder.parise, commentViewHolder.pariseNumber, commitDataBean, position);
                    setOnUnPraiseListener(commentViewHolder.down, commentViewHolder.downNumber, commitDataBean, position);

//                     setOnPraiseListener(commentViewHolder, commentViewHolder.parise, commentViewHolder.pariseNumber, commitDataBean, position);
//                     setOnUnPraiseListener(commentViewHolder, commentViewHolder.down, commentViewHolder.downNumber, commitDataBean, position);
                    setOnItemListener(commentViewHolder.message, commitDataBean);
                    setOnItemListener(commentViewHolder.commentAllRootLl, commitDataBean);

                    //动态判断设置行数
                    if (commitDataBean.isShowMore()) {
                        commentViewHolder.more.setText("收起");
                        commentViewHolder.content.setMaxLines(Integer.MAX_VALUE);
                    } else {
                        commentViewHolder.more.setText("查看全部");
                        commentViewHolder.content.setMaxLines(5);
                    }

                    final CommentViewHolder finalCommentViewHolder1 = commentViewHolder;
                    commentViewHolder.content.post(new Runnable() {
                        @Override
                        public void run() {
                            Layout l = finalCommentViewHolder1.content.getLayout();
                            if (l != null) {
                                int lines = l.getLineCount();
                                if (lines > 0) {
                                    if (lines > 5) {
                                        finalCommentViewHolder1.more.setVisibility(View.VISIBLE);
                                    } else {
                                        int num = l.getEllipsisCount(lines - 1);
                                        if (num > 0) {
                                            finalCommentViewHolder1.more.setVisibility(View.VISIBLE);
                                        } else {
                                            if (commitDataBean.isShowMore()) {
                                                finalCommentViewHolder1.more.setVisibility(View.VISIBLE);
                                            } else {
                                                finalCommentViewHolder1.more.setVisibility(View.GONE);
                                            }
                                        }
                                    }
                                }
                            } else {
                                finalCommentViewHolder1.more.setVisibility(View.GONE);
                            }
                        }
                    });

                    //监听点击"查看全部"按钮点击事件
                    final CommentViewHolder finalCommentViewHolder = commentViewHolder;
                    commentViewHolder.more.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            String s = finalCommentViewHolder.more.getText().toString();
                            if (s.equals("查看全部")) {
                                if (android.os.Build.VERSION.SDK_INT == 19) {
                                    finalCommentViewHolder.content.setText(commitDataBean.getContent());
                                }
                                finalCommentViewHolder.content.setMaxLines(Integer.MAX_VALUE);
                                finalCommentViewHolder.more.setText("收起");
                                commitDataBean.setShowMore(true);
                            } else {
                                if (android.os.Build.VERSION.SDK_INT == 19) {
                                    finalCommentViewHolder.content.setText(commitDataBean.getContent().replaceAll("\n", ""));
                                }
                                finalCommentViewHolder.content.setMaxLines(5);
                                finalCommentViewHolder.more.setText("查看全部");
                                commitDataBean.setShowMore(false);
                            }
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case ViewType.COMMIT_FOOTER:
                ViewHolderGCommitFoot holderGCommitFoot = (ViewHolderGCommitFoot) holder;
                if (gameInfoDetial.getGame_comment_switch() == 1) {
                    holderGCommitFoot.commentFooterLayout.setVisibility(View.VISIBLE);
                } else {
                    holderGCommitFoot.commentFooterLayout.setVisibility(View.GONE);
                }
                holderGCommitFoot.commentFooterLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent("gameDetialShowCommentTab");
                        view.getContext().sendBroadcast(intent);
                    }
                });
//                 holderGCommitFoot.goforum.setOnClickListener(new View.OnClickListener() {
//                     @Override
//                     public void onClick(View view) {
//                         IntentUtil.getInstance().goForumFid(context, (int) modleFourBean.getForum_id());
//                     }
//                 });
                break;
            case ViewType.NO_COMMIT:

                break;
            case ViewType.WEBVIEW:
                ViewHolderWEB holderWEB = (ViewHolderWEB) holder;
//                lodeWebView(holderWEB.webView,mContext,"http://www.baidu.com");
                lodeWebView(holderWEB.webView, mContext, gameInfoDetial.getGame_diagram());
//                holderWEB.webView.setBackgroundColor(0xffffffff);
                break;
        }

    }

    private void lodeWebView(WebView web, final Activity context, String url) {
        try {
            if (NetWorkUtils.isNetworkConnected(context)) {
                if (web == null) return;

                web.setVisibility(View.VISIBLE);
//                web.getSettings().setBarHeight(context.getResources().getDimensionPixelOffset(R.dimen.wdp6));
                web.setClickable(true);
                web.getSettings().setUseWideViewPort(true);
                web.getSettings().setSupportZoom(false);
                web.getSettings().setBuiltInZoomControls(false);
                web.getSettings().setJavaScriptEnabled(true);
                web.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);

                web.setWebViewClient(new WebViewClientYQW(context, new WebViewClientYQW.WebViewClientInterface() {
                    @Override
                    public void setUrl(String url) {
                    }

                    @Override
                    public void showLoding() {
                    }

                    @Override
                    public void showLodingFailed() {
                    }
                }));

                web.addJavascriptInterface(new WebJSPInterfaceMethedBean(context, web, new WebJSPInterfaceMethedBean.WebJsInterface() {
                    @Override
                    public void showTitle(boolean showTile) {

                    }

                    @Override
                    public void setTitleText(String titleText) {

                    }

                    @Override
                    public void setFullScreen(boolean isfullScreen) {

                    }
                }), "yiqiwan");
                web.loadUrl(url);
            } else {
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private void setOnPraiseListener(final ImageView view, final TextView tv, final CommentBaseBean commitDataBean, final int position) {
        View.OnClickListener temp = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
//                if (AccountUtil_.getInstance_(context).isTourist()) {
//                    DialogUtil_.getInstance_(context).getAccountLoginDialogForCommon(context
//                            , context.getResources().getString(R.string.comment_login_tx), "登录", "取消", null);
//                    return;
//                }
                if (AccountUtil.getInstance().getUidNotToLogin(mContext) == 0) return;
                if (commitDataBean == null)
                    return;
                if (commitDataBean.getIs_praise() == 1) {
                    subPraise(position);
                    view.setImageResource(R.drawable.up_ic);
                    if (mListenr != null) {
                        mListenr.onPraise(commitDataBean, position, 2);
                    }
                    return;
                } else {
                    commitDataBean.setIs_praise(1);
                }

                if (AccountUtil.getInstance().getAccountData() != null) {
                    view.setImageResource(R.drawable.uped_ic);
                    Animation scaleAnim = AnimationUtils.loadAnimation(mContext, R.anim.scale_reset);
                    view.startAnimation(scaleAnim);
                    scaleAnim.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            long num = Long.valueOf(tv.getText().toString());
                            tv.setText((num + 1) + "");
                            addPraise(position);

                            if (mListenr != null) {
                                mListenr.onPraise(commitDataBean, position, 1);
                            }
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });
                } else {
//                    IntentUtil.getInstance().goMyAccountLoginActivity(context, 0, 2);
                    IntentUtil.getInstance().goLoginInteractive(mContext);
                }
            }
        };

        view.setOnClickListener(temp);
        tv.setOnClickListener(temp);
    }

    private CommentBaseBean getItem(int position) {
        CommentBaseBean commitDataBean = (CommentBaseBean) gameListdata.get(position).object;
        return commitDataBean;
    }

    public void addPraise(int position) {
        CommentBaseBean viewBean = (CommentBaseBean) getItem(position);

        long num = viewBean.getPraise_count();
        viewBean.setIs_praise(1);
        viewBean.setPraise_count(num + 1);
        notifyDataSetChanged();
    }

    public void subPraise(int position) {
        CommentBaseBean viewBean = (CommentBaseBean) getItem(position);

        long num = viewBean.getPraise_count();
        viewBean.setIs_praise(0);
        if (num - 1 < 0)
            viewBean.setPraise_count(0);
        else
            viewBean.setPraise_count(num - 1);
        notifyDataSetChanged();
    }

    public void resetPraise(int position, int state) {
        CommentBaseBean viewBean = (CommentBaseBean) getItem(position);

        long num = viewBean.getPraise_count();
        if (viewBean.getIs_praise() == 1) {
            viewBean.setIs_praise(0);
            if (num - 1 < 0)
                viewBean.setPraise_count(0);
            else
                viewBean.setPraise_count(num - 1);
        } else {
            if (state != 1) {
                viewBean.setIs_praise(1);
                viewBean.setPraise_count(num + 1);
            }
        }
        notifyDataSetChanged();
    }

    public void resetDespise(int position, int state) {
        CommentBaseBean viewBean = getItem(position);
        long num = Long.valueOf(viewBean.getDespise_count());
        if (viewBean.getIs_despise() == 1) {
            viewBean.setIs_despise(0);
            if (num - 1 < 0)
                viewBean.setDespise_count("0");
            else
                viewBean.setDespise_count(num - 1 + "");
        } else {
            if (state != 1) {
                viewBean.setIs_despise(1);
                viewBean.setDespise_count(num + 1 + "");
            }
        }
        notifyDataSetChanged();
    }

    public void addDespise(int position) {
        CommentBaseBean viewBean = (CommentBaseBean) getItem(position);

        long num = Long.valueOf(viewBean.getDespise_count());
        viewBean.setIs_despise(1);
        viewBean.setDespise_count(num + 1 + "");
        notifyDataSetChanged();
    }

    public void subDespise(int position) {
        CommentBaseBean viewBean = (CommentBaseBean) getItem(position);

        long num = Long.valueOf(viewBean.getDespise_count());
        viewBean.setIs_despise(0);
        if (num - 1 < 0)
            viewBean.setDespise_count("0");
        else
            viewBean.setDespise_count(num - 1 + "");
        notifyDataSetChanged();
    }

    private View animVIew;

    public View getAminView() {
        return animVIew;
    }

    private void setOnUnPraiseListener(final ImageView view, final TextView tv, final CommentBaseBean commitDataBean, final int position) {
        View.OnClickListener temp = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
//                if (AccountUtil_.getInstance_(context).isTourist()) {
//                    DialogUtil_.getInstance_(context).getAccountLoginDialogForCommon(context
//                            , context.getResources().getString(R.string.comment_login_tx), "登录", "取消", null);
//                    return;
//                }
                if (AccountUtil.getInstance().getUidNotToLogin(mContext) == 0) return;
                if (commitDataBean == null)
                    return;
                if (commitDataBean.getIs_despise() == 1) {
                    subDespise(position);
                    view.setImageResource(R.drawable.down_ic);
                    if (mListenr != null) {
                        mListenr.onUnPraise(commitDataBean, position, 2);
                    }
                    return;
                } else {
                    commitDataBean.setIs_despise(1);
                }

                if (AccountUtil.getInstance().getAccountData() != null) {
                    view.setImageResource(R.drawable.downed_ic);
                    Animation scaleAnim = AnimationUtils.loadAnimation(mContext, R.anim.scale_reset);
                    view.startAnimation(scaleAnim);
                    scaleAnim.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            long num = Long.valueOf(tv.getText().toString());
                            tv.setText((num + 1) + "");
                            addDespise(position);

                            if (mListenr != null) {
                                mListenr.onUnPraise(commitDataBean, position, 1);
                            }
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });
                } else {
//                    IntentUtil.getInstance().goMyAccountLoginActivity(context, 0, 2);
                    IntentUtil.getInstance().goLoginInteractive(mContext);
                }
            }
        };
        view.setOnClickListener(temp);
        tv.setOnClickListener(temp);
    }

    @Override
    public int getItemCount() {
        return gameListdata.size();
    }

    @Override
    public int getItemViewType(int position) {

        return gameListdata.get(position).itemType;
    }

    public void setListenr(Listener mListenr) {
        this.mListenr = mListenr;
    }


    public class GamedetialItemMain {
        public Object object;
        public int itemType;

        public GamedetialItemMain(Object object, int itemType) {
            this.object = object;
            this.itemType = itemType;
        }
    }

    class ViewHolderGCommitFoot extends ViewHolderGameDetialMain {
        RelativeLayout commentFooterLayout;
        TextView showAllCommit;
        TextView goforum;

        public ViewHolderGCommitFoot(View itemView) {
            super(itemView);
            commentFooterLayout = (RelativeLayout) itemView.findViewById(R.id.commentFooterLayout);
            showAllCommit = (TextView) itemView.findViewById(R.id.showAllCommit);
            goforum = (TextView) itemView.findViewById(R.id.goforum);
        }
        //TODO:胡泽银注释
//        RelativeLayout commentFooterLayout;
//
//        public ViewHolderGCommitFoot(View itemView) {
//            super(itemView);
//            commentFooterLayout = (RelativeLayout) itemView.findViewById(R.id.commentFooterLayout);
//        }
    }

    class ViewHolderNO_COMMIT extends ViewHolderGameDetialMain {

        public ViewHolderNO_COMMIT(View itemView) {
            super(itemView);

        }
    }

    class CommentViewHolder extends ViewHolderGameDetialMain {
        private LinearLayout commentAllRootLl;

        private SimpleDraweeView userIcon;
        private TextView userName;
        private TextView isMe;
        private ImageView isAuth;
        private TextView isConnoisseurs;
        private MStarBar comment_head_mstarBar;
        private TextView comment_head_num_tx;
        private TextView time;
        private ImageView isGood;
        private TextView content;
        private TextView more;
        public View line;
        private TextView phoneModle;
        private ImageView parise;
        private TextView pariseNumber;
        private ImageView down;
        private TextView downNumber;
        private ImageView message;
        private TextView messageNumber;
        private VipView levelTv;
        private View layoutTop;

        public CommentViewHolder(View view) {
            super(view);
            commentAllRootLl = (LinearLayout) view.findViewById(R.id.commentAllRootLl);
            userIcon = (SimpleDraweeView) view.findViewById(R.id.usericon);
            userName = (TextView) view.findViewById(R.id.userName);
            isMe = (TextView) view.findViewById(R.id.isMe);
            isAuth = (ImageView) view.findViewById(R.id.isAuth);
            isGood = (ImageView) view.findViewById(R.id.isGood);
            isConnoisseurs = (TextView) view.findViewById(R.id.isConnoisseurs);
            comment_head_mstarBar = (MStarBar) view.findViewById(R.id.comment_head_mstarBar);
            comment_head_num_tx = (TextView) view.findViewById(R.id.comment_head_num_tx);
            time = (TextView) view.findViewById(R.id.time);
            content = (TextView) view.findViewById(R.id.content);
            more = (TextView) view.findViewById(R.id.more);
//            line = view.findViewById(R.id.line);
            phoneModle = (TextView) view.findViewById(R.id.phoneModle);
            parise = (ImageView) view.findViewById(R.id.parise);
            pariseNumber = (TextView) view.findViewById(R.id.pariseNumber);
            down = (ImageView) view.findViewById(R.id.down);
            downNumber = (TextView) view.findViewById(R.id.downNumber);
            message = (ImageView) view.findViewById(R.id.message);
            messageNumber = (TextView) view.findViewById(R.id.messageNumber);
            levelTv = (VipView) view.findViewById(R.id.levelTv);
            layoutTop = view.findViewById(R.id.layoutTop);
        }
    }

    class ViewHolderGGameDescribe extends ViewHolderGameDetialMain {
        TextView htmlGameDescribe;
        TextView textMore;

        public ViewHolderGGameDescribe(View itemView) {
            super(itemView);
            htmlGameDescribe = (TextView) itemView.findViewById(R.id.htmlGameDescribe);
            textMore = (TextView) itemView.findViewById(R.id.textMore);
        }
    }

    class ViewHolderGViewPage extends ViewHolderGameDetialMain {
        //        DetialImgRecycleView screenListView;
        HListView screenListView;

        public ViewHolderGViewPage(View itemView) {
            super(itemView);
            screenListView = itemView.findViewById(R.id.screenListView);
        }
    }

    class ViewHolderGTitle extends ViewHolderGameDetialMain {
        public TextView titleText;
        public LinearLayout look_other;
        public View layoutTop;
        public View line_h;

        public ViewHolderGTitle(View itemView) {
            super(itemView);
            titleText = (TextView) itemView.findViewById(R.id.titleText);
            line_h = itemView.findViewById(R.id.line_h);
            look_other = (LinearLayout) itemView.findViewById(R.id.look_other);
            layoutTop = itemView.findViewById(R.id.layoutTop);
        }
    }

    class ViewHolderAD extends ViewHolderGameDetialMain {
        public LinearLayout scrollViewAd;


        public ViewHolderAD(View itemView) {
            super(itemView);
            scrollViewAd = itemView.findViewById(R.id.scrollViewAd);
        }
    }

    class ViewHolderWEB extends ViewHolderGameDetialMain {
        public ObservableWebView webView;


        public ViewHolderWEB(View itemView) {
            super(itemView);
            webView = itemView.findViewById(R.id.webview);
        }
    }

    public class ViewType {
        public static final int IMAGES = 5;
        public static final int DESCRIBE = 8;
        public static final int ITEMTITLE = 1;
        public static final int COMMENTITEM = 25;
        public static final int NO_COMMIT = 26;
        public static final int COMMIT_FOOTER = 16;
        public static final int ADVIEW = 27;
        public static final int WEBVIEW = 28;

    }

    private void setOnItemListener(View view, final CommentBaseBean commitDataBean) {
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (commitDataBean == null)
                    return;
                if (mListenr != null) {
                    mListenr.onRootView(commitDataBean);
                }
            }
        });
    }

    public interface Listener {
//        void onPraise(InformationCommentBean bean);
//        //TODO:胡泽银注释
////        void onPraise(GameCommitListBean.GameCommitList bean);
//
//        void onReplyReply(InformationCommentBean.Sub sub);
//
//        void onReply(InformationCommentBean bean);


        /**
         * 快速评论->发帖
         */
        void onPostingClick();


        void onPraise(CommentBaseBean bean, int position, int type);//点赞

        void onUnPraise(CommentBaseBean bean, int position, int type);//点踩

        void onRootView(CommentBaseBean bean);//item
    }

    class MyAdAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return 10;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                View view = LayoutInflater.from(mContext).inflate(R.layout.gamedetail_ad_item_child, null);

            } else {

            }
            return null;
        }
    }
}
